package com.wench.completable;

import java.util.concurrent.CompletableFuture;

public class CompletableFutureDemo {

    public static void main(String[] args) throws Exception {

        //  同步调用
        CompletableFuture<Void> completableFuture01 = CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName() + " : CompletableFuture01");
        });
        completableFuture01.get();

        //  异步调用
        CompletableFuture<Integer> completableFuture02 = CompletableFuture.supplyAsync(() -> {
            System.out.println(Thread.currentThread().getName() + " : CompletableFuture02");
            return 1024;
        });
        completableFuture02.whenComplete((t, u) -> {
            System.out.println("t = " + t + ", u = " + u);
        }).get();
    }
}
